/*
 * @Descripttion: 医师获取自己的预约列表
 * @version: 1.0
 * @Author: 自由如风
 * @Date: 2021-05-06 22:21:15
 * @LastEditors: 自由如风
 * @LastEditTime: 2021-05-06 22:26:38
 */

const DB = require('../../lib/DB');
const { Success, Fail } = require('../../lib/Response');

module.exports = async function (ctx, next) {
    try {
        const foresee_list = (await DB.models.foresee.findAll({
            where: { doctor_id: ctx.session.doctor.id }, include: [
                {
                    model: DB.models.user,
                    as: 'doctor'
                }, {
                    model: DB.models.patient,
                    as: 'patient'
                }
            ], limit: 30
        })).map(e => e.toJSON());

        ctx.body = new Success(foresee_list)

    } catch (e) {
        ctx.body = new Fail(e.message)
    }
}
